package br.com.baco.evento.gui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import br.com.baco.R;
import br.com.baco.evento.EventoFactory;
import br.com.baco.evento.dominio.Evento;
import br.com.baco.evento.negocio.IEventoServices;

public class VisualizarEventoActivity extends ActionBarActivity {
	private IEventoServices eventoServices = EventoFactory.getInstance().createServices(this);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_visualizar_evento);
		
		Intent intent = getIntent();
		
		intent.getExtras();
		
		Bundle params = intent.getExtras();  
		this.setInformacoes( Integer.parseInt( params.getString("id") ) );
    }
	
	public void setInformacoes(Integer idEvento){
		Evento evento = eventoServices.visualizar(idEvento);
		
		TextView textTitulo = (TextView)findViewById(R.id.campo_evento_visualizar_nome);
		textTitulo.setText(evento.getNome());
		
		TextView textData = (TextView)findViewById(R.id.campo_evento_visualizar_data);
		textData.setText(evento.getData());
		
		TextView textHorario = (TextView)findViewById(R.id.campo_evento_visualizar_hora);
		textHorario.setText(evento.getHorario());
		
		TextView textConvidados = (TextView)findViewById(R.id.campo_evento_visualizar_convidados);
		textConvidados.setText(evento.getQuantConvidados());
		
		TextView textTipo = (TextView)findViewById(R.id.campo_evento_visualizar_tipo);
		textTipo.setText(evento.getTipo());
	
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.listar_eventos, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	@Override
	public void onBackPressed() {
	    // do something on back.
		Intent back = new Intent(this, ListarEventosActivity.class);
		startActivity(back);
        finish();
	    
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.activity_visualizar_evento,
					container, false);
			return rootView;
		}
	}

}
